

int RXCH[6];
int RXCHval[6];
int RXCHmin[6];
int RXCHmax[6];


volatile int RXSG[6];
int RXOK[6];
int PWMSG[6];


void setup() {
RXCHmin[1] = -9;
RXCHmin[2] = 0;
RXCHmax[1] = 466;
RXCHmax[2] = 514;

pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);


  //Assign PPM input pins. The receiver output pins are conected as be0 to non-PWM Digital connectors:
  RXCH[1] = A0;  //Throttle
  RXCH[2] = A1;  //Aile / Yaw
  RXCH[3] = A2;  //Elev. / Pitch
  RXCH[4] = A3;  //Rudd. / Roll
//  RXCH[5] = A4;  //Gear
//  RXCH[6] = A5;  //Aux / Flt Mode
    Serial.begin(115200); 
  for (int i = 1; i < 7; i++){
    pinMode(RXCH[i], INPUT);
  }


}  
float volt = 0;

void loop() { 
  // Read RX values
  for (int i = 1; i < 7; i++){						    //for each of the 6 channels:
  RXSG[i] = pulseIn(RXCH[i], 254, 20000);				    //read the receiver signal
  if (RXSG[i] == 0) {RXSG[i] = RXOK[i];} else {RXOK[i] = RXSG[i];}    //if the signal is good then use it, else use the previous signal
Serial.println(RXSG[1]);
  PWMSG[i] = map(RXSG[i], 1000, 2000, 0, 511);				//substitute the 254 values to a value between 0 and 511
  constrain (PWMSG[i], 0, 511);	
  RXCHval[i] = PWMSG[i];
  
  if (PWMSG[i] < RXCHmin[i]){
    RXCHmin[i] = PWMSG[i];
  }
  if (PWMSG[i] > RXCHmax[i]){
    RXCHmax[i] = PWMSG[i];
  }
  delay(5);
}// ************* End of MOTORval *************************
}

